package myWebApp;

/*第三章 垃圾收集器
 *测试是否采用引用计数算法进行垃圾回收
 *jvm参数:-XX:+PrintGC -XX:+PrintGCDetails
 *2017年8月4日19:45:40
 */
public class GC1 {
	
	public Object instance = null;
	
	private byte[] size = new byte[2*1024*1024];
	
	public static void get() {
		GC1 AGC = new GC1();                                                                                                      
		GC1 BGC = new GC1();
		AGC.instance = BGC;
		BGC.instance = AGC;
		
		AGC = null;
		BGC = null;
		
		System.gc();
	}
	
	public static void main(String[] args) {
		get();
	}
	
}

/*日志信息
 * 
[GC (System.gc()) [PSYoungGen: 6093K->728K(38400K)] 6093K->736K(125952K), 0.0008740 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 728K->0K(38400K)] [ParOldGen: 8K->594K(87552K)] 736K->594K(125952K), [Metaspace: 2539K->2539K(1056768K)], 0.0043176 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 38400K, used 333K [0x00000000d5c00000, 0x00000000d8680000, 0x0000000100000000)
  eden space 33280K, 1% used [0x00000000d5c00000,0x00000000d5c534a8,0x00000000d7c80000)
  from space 5120K, 0% used [0x00000000d7c80000,0x00000000d7c80000,0x00000000d8180000)
  to   space 5120K, 0% used [0x00000000d8180000,0x00000000d8180000,0x00000000d8680000)
 ParOldGen       total 87552K, used 594K [0x0000000081400000, 0x0000000086980000, 0x00000000d5c00000)
  object space 87552K, 0% used [0x0000000081400000,0x0000000081494b78,0x0000000086980000)
 Metaspace       used 2545K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 271K, capacity 386K, committed 512K, reserved 1048576K
 
 6093K->763K证明了约4M的堆内存被回收
 */

